package com.znufe.exam.controller.admin;

import java.util.List;

import com.znufe.exam.viewmodel.admin.classinteraction.ClassInteractionQASituationRequestVM;
import com.znufe.exam.viewmodel.admin.classinteraction.ClassInteractionQASituationResponseVM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.znufe.exam.domain.ClassInteractionCustomerAnswer;
import com.znufe.exam.service.ClassInteractionCustomerAnswerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import com.znufe.exam.base.RestResponse;
import com.znufe.exam.base.SystemCode;

/**   
 * 
 * @Description:  课堂互动答题详情信息接口层
 * @Author:       lin keqing   
 * @CreateDate:   ClassInteractionCustomerAnswer
 * @Version:      V1.0
 *    
 */
@Api(description = "课堂互动答题详情信息",value="课堂互动答题详情信息" )
@RestController
@RequestMapping("/api/admin/class_interaction")
public class ClassInteractionCustomerAnswerController {

	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	public ClassInteractionCustomerAnswerService classInteractionCustomerAnswerService;

	@RequestMapping(value = "/get_question_answer_situation", method = RequestMethod.POST, produces = "application/json")
	@ApiOperation(value = "通过班级id、课程id、试卷类别、题目id获得某个班级某个课程上课堂互动答题情况统计",
			notes = "获取某个班的某张试卷的答题情况统计[class_interaction_customer_answer]，作者：lin keqing")
	public RestResponse<List<ClassInteractionQASituationResponseVM>> getQuestionAnswerSituation(@RequestBody ClassInteractionQASituationRequestVM model) {
		List<ClassInteractionQASituationResponseVM> vmList = classInteractionCustomerAnswerService
				.selectClassInteractionQASituation(model);
		if (vmList.isEmpty()) {
			return RestResponse.fail(2,"该题还未有学生作答，请学生们作答该题！");
		}
		return RestResponse.ok(vmList);
	}


	/**
	 * @explain 查询课堂互动答题详情信息对象  <swagger GET请求>
	 * @param   id
	 * @return  classInteractionCustomerAnswer
	 * @author  lin keqing
	 * @time    ClassInteractionCustomerAnswer
	 */
	@GetMapping("/getClassInteractionCustomerAnswerById/{id}")
	@ApiOperation(value = "获取课堂互动答题详情信息信息", notes = "获取课堂互动答题详情信息信息[classInteractionCustomerAnswer]，作者：lin keqing")
	@ApiImplicitParam(paramType="path", name = "id", value = "课堂互动答题详情信息id", required = true, dataType = "Integer")
	public RestResponse<ClassInteractionCustomerAnswer> getClassInteractionCustomerAnswerById(@PathVariable("id")Integer id){

		try {
			ClassInteractionCustomerAnswer classInteractionCustomerAnswer=classInteractionCustomerAnswerService.selectByPrimaryKey(id);
			if (classInteractionCustomerAnswer!=null) {
				return RestResponse.ok(classInteractionCustomerAnswer);
			} else {
				logger.error("查询课堂互动答题详情信息执行失败："+classInteractionCustomerAnswer.toString());
				return RestResponse.fail(SystemCode.NoDataExist.getCode(),SystemCode.NoDataExist.getMessage());
			}
		} catch (Exception e) {
			logger.error("查询课堂互动答题详情信息执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 添加课堂互动答题详情信息对象
	 * @param   classInteractionCustomerAnswer
	 * @return  int
	 * @author  lin keqing
	 * @time    ClassInteractionCustomerAnswer
	 */
	@PostMapping("/insertSelective")
	@ApiOperation(value = "添加课堂互动答题详情信息", notes = "添加课堂互动答题详情信息[classInteractionCustomerAnswer],作者：lin keqing")
	public RestResponse<Integer> insertSelective(@RequestBody ClassInteractionCustomerAnswer classInteractionCustomerAnswer){
		try {
			int rg=classInteractionCustomerAnswerService.insertSelective(classInteractionCustomerAnswer);
			if (rg>0) {
				return RestResponse.ok(rg);
			} else {
				logger.error("添加课堂互动答题详情信息执行失败："+classInteractionCustomerAnswer.toString());
				return RestResponse.fail(SystemCode.InsertDataFail.getCode(),SystemCode.InsertDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("添加课堂互动答题详情信息执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 删除课堂互动答题详情信息对象
	 * @param   id
	 * @return  int
	 * @author  lin keqing
	 * @time    ClassInteractionCustomerAnswer
	 */
	@PostMapping("/deleteByPrimaryKey")
	@ApiOperation(value = "删除课堂互动答题详情信息", notes = "删除课堂互动答题详情信息,作者：lin keqing")
	@ApiImplicitParam(paramType="query", name = "id", value = "课堂互动答题详情信息id", required = true, dataType = "Integer")
	public RestResponse<Integer> deleteByPrimaryKey(Integer id){
		try {
			int reg=classInteractionCustomerAnswerService.deleteByPrimaryKey(id);
			if (reg>0) {
				return RestResponse.ok(reg);
			} else {
				logger.error("删除课堂互动答题详情信息失败ID："+id);
				return RestResponse.fail(SystemCode.DeleteDataFail.getCode(),SystemCode.DeleteDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("删除课堂互动答题详情信息执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 修改课堂互动答题详情信息对象
	 * @param   classInteractionCustomerAnswer
	 * @return  classInteractionCustomerAnswer
	 * @author  lin keqing
	 * @time    ClassInteractionCustomerAnswer
	 */
	@ApiOperation(value = "修改课堂互动答题详情信息", notes = "修改课堂互动答题详情信息[classInteractionCustomerAnswer],作者：lin keqing")
	@PostMapping("/updateByPrimaryKeySelective")
	public RestResponse<Integer> updateByPrimaryKeySelective(ClassInteractionCustomerAnswer classInteractionCustomerAnswer){
		try {
			int reg = classInteractionCustomerAnswerService.updateByPrimaryKeySelective(classInteractionCustomerAnswer);
			if (reg>0) {
				return RestResponse.ok(reg);
			} else {
				logger.error("修改课堂互动答题详情信息失败ID："+classInteractionCustomerAnswer.toString());
				return RestResponse.fail(SystemCode.UpdateDataFail.getCode(),SystemCode.UpdateDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("修改课堂互动答题详情信息执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 获取匹配课堂互动答题详情信息
	 * @param   classInteractionCustomerAnswer
	 * @return  List<ClassInteractionCustomerAnswer>
	 * @author  lin keqing
	 * @time    ClassInteractionCustomerAnswer
	 */
	@ApiOperation(value = "条件查询课堂互动答题详情信息", notes = "条件查询[classInteractionCustomerAnswer],作者：lin keqing")
	@PostMapping("/queryClassInteractionCustomerAnswerList")
	public RestResponse<List<ClassInteractionCustomerAnswer>> queryClassInteractionCustomerAnswerList(ClassInteractionCustomerAnswer classInteractionCustomerAnswer){
		try {
			List<ClassInteractionCustomerAnswer> list = classInteractionCustomerAnswerService.queryClassInteractionCustomerAnswerList(classInteractionCustomerAnswer);
			return RestResponse.ok(list);
		} catch (Exception e) {
			logger.error("获取课堂互动答题详情信息执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}

}